package com.app.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.app.mapper.PayMapper;
import com.app.model.PayModel;
import com.app.service.PayService;
import com.app.vo.PayVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PayServiceImpl extends ServiceImpl<PayMapper, PayModel> implements PayService {
    @Autowired
    private PayMapper payMapper;

    @Override
    public PayVo getVipList(Integer page, Integer limit, String keyword, String startTime, String endTime, String areaId, String cityId) {
        page = (page - 1) * limit;
        List<PayModel> payModelList = payMapper.getVipList(page, limit, keyword, startTime, endTime, areaId, cityId);
        for (PayModel payModel : payModelList) {
            payModel.setAreaText(payModel.getProvince() + "/" + payModel.getCity() + "/" + payModel.getArea());
        }
        Integer count = payMapper.getVipCount(keyword, startTime, endTime);
        PayVo vo = new PayVo();
        vo.setList(payModelList);
        vo.setCount(count);
        return vo;
    }

    @Override
    public IPage<PayModel> getVipListByPage(Integer page, Integer limit,  String startTime, String endTime, Integer areaId, Integer cityId) {
        Page<PayModel> payModelPage=new Page<>(page,limit);
        IPage<PayModel> payModelList = payMapper.getVipListByPage(payModelPage,  startTime, endTime, areaId, cityId);
        if(CollectionUtil.isNotEmpty(payModelList.getRecords()))
        {
            for (PayModel payModel : payModelList.getRecords()) {
                payModel.setAreaText(payModel.getProvince() + "/" + payModel.getCity() + "/" + payModel.getArea());
            }
        }

        return payModelList;
    }
}
